<?php
namespace Admin\Controller;
use Think\Controller;
/**
 * 广告管理控制器
 */
class AdvertisementController extends AdminController{
	/**
	 * 广告列表
	 */
	public function index(){
		$page=I('get.page','1','strip_tags');
            $count=M('advertisement')->count();
             $pagearr= getPageArr($page,C('PAGESIZE'),$count);
             $re=M('advertisement')->limit($pagearr['start'],$pagearr['pagesize'])->select();
             $this->assign("re",$re);
             $this->assign('pagearr',$pagearr);
             $this->display();
	}


	/**
	 * 添加广告
	 */
	public function append(){
		if(IS_POST){
		/*$config['path']=C('Admin_IMG_PATH');
		$config['maxsize']=C('IMG_MAX_SIZE');
		$img=imgUpload($config);
		$imginfo=$img['advimg'];
		if(!empty($imginfo['savename']))
		{
			$data['advimg']=C('Admin_IMG_PATH').$imginfo['savepath'].$imginfo['savename'];
			$this->assign('advimg',$data);

		}
		$data['advname']=I("post.advname",'','strip_tags');
		$data['description']=I("post.description",'','strip_tags');
		$re=M('advertisement')->add($data);
		if($re>0){
			$this->redirect("Advertisement/index");
		}*/
		}else{
		$this->display();}

	}

	/**
	 * 删除广告
	 */
	public function move(){
		$where['id']=$_GET['id'];
   	$row=M('advertisement')->where($where)->delete();
    echo "<script>alert('广告删除成功');location.href='/index.php/Admin/Advertisement/index'</script>";
	}


	/**
	 * 编辑
	 */
	public function edit(){
		if(IS_POST){
			
			$where['id']=$_GET['id'];
		$config['path']=C('Admin_IMG_PATH');
    $config['maxsize']=C('IMG_MAX_SIZE');
    $img=imgUpload($config);
    $imginfo=$img['advimg'];
    if(!empty($imginfo['name']))
    {
      $data['advimg']=C('Admin_IMG_PATH').$imginfo['savepath'].$imginfo['savename'];
    }
    $data['advname']=I("post.advname",'','strip_tags');
    $data['description']=I("post.description",'','strip_tags');
    $re=M('advertisement')->where($where)->save($data);
    
    if($re){
    	$this->redirect("advertisement/index");
    }

		}else{
			$where['id']=$_GET['id'];
			$res=M('advertisement')->where($where)->find();
			$this->assign('res',$res);

			$this->display();
		
		


	}
}



}